package com.sysware.neo4jdemo.controller;

import com.sysware.neo4jdemo.entity.User;
import com.sysware.neo4jdemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@Api(value = "NodeController", tags = {"节点操作"})
@RestController
@RequestMapping("/rest/coder")
public class NodeController {

    @Autowired
    UserService userService;

    @ApiOperation(value = "getCoderByName", notes = "通过name获取user")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "coder name", required = true, dataType = "string")
    })
    @GetMapping("/get/{name}")
    public User getCoderByName(@RequestParam(value = "name") String name) {
        return userService.getUserByName(name);
    }

    @ApiOperation(value = "initData", notes = "初始化数据")
    @PostMapping("/initData")
    public String initData() {
        userService.initData();
        return "success";
    }

    @ApiOperation(value = "deleteAll", notes = "清空数据")
    @PostMapping("/deleteAll")
    @Transactional
    public String deleteAll() {
        userService.deleteAll();
        return "clearAll success!";
    }

}
